<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\ColumnRequest;
use App\Model\Column;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ColumnController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        $columns = Column::get();
        return view('admin.column.index',compact('columns'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {

        return view('admin.column.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(ColumnRequest $request,Column $column)
    {
//        dd($request->toArray());
        $column->create($request->all());
        return redirect()->route('admin.column.index')->with('success','添加成功');
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Model\Column  $column
     * @return \Illuminate\Http\Response
     */
    public function show(Column $column)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Model\Column  $column
     * @return \Illuminate\Http\Response
     */
    public function edit(Column $column)
    {
            return view('admin.column.edit',compact('column'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Model\Column  $column
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Column $column)
    {
//        dd($request->toArray());
        $column->update($request->all());
        return redirect()->route('admin.column.index')->with('success','编辑成功');

    }


    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Model\Column  $column
     * @return \Illuminate\Http\Response
     */
    public function destroy(Column $column)
    {
        $column->delete();

        return redirect()->route('admin.column.index')->with('success','删除成功');
    }
}
